﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MaxLib
{
    public abstract class Unit
    {
        public abstract ICollection<UnitClass> AllClasses { get; }

        public void AddClass(UnitClass newClass)
        {
            newClass.addToUnit(this);
        }
    }

    public abstract class UnitClass
    {
        public virtual void addToUnit(Unit unit)
        {
            unit.AllClasses.Add(this);
        }
    }

    public class Soldier : UnitClass
    {

    }

    public class Mage : UnitClass
    {
        public override void addToUnit(Unit unit)
        {
            // Can Upgrade to Mage
            bool hasSoldier = false;
            foreach (UnitClass c in unit.AllClasses)
            {
                if (c is Soldier)
                    hasSoldier = true;
            }

            if (hasSoldier)
            {
                base.addToUnit(unit);
            }
            else
            {
                Console.WriteLine("Requires Soldier.");
            }
        }
    }

    public class MainCharacter : Unit
    {
        private List<UnitClass> myClasses;

        public MainCharacter()
        {
            myClasses = new List<UnitClass>();
        }

        public override ICollection<UnitClass> AllClasses
        {
            get { return myClasses; }
        }
    }

    class FinalExamples
    {
    }
}
